<template>
  <div class="three-col-item-wrap j_akc_ubt" @click="goProductDetail">
    <div class="img-wrap-box">
      <img v-lazy="imgUrl" />
      <!-- [省赚]组件 -->
      <profit
        v-if="isUserOfB && product.profit"
        class="profit--private"
        :profitObj="product"
      ></profit>
      <div v-if="product.sellOut" class="sellout">
        售罄
      </div>
      <!-- 打标 -->
      <img
        v-if="product.productSubscriptUrl"
        class="mark-img"
        :src="product.productSubscriptUrl"
      />
    </div>
    <div class="product-info-wrap">
      <p class="product-des more_text">
        {{ product.productName || '' }}
      </p>
      <div class="price-cart">
        <div class="price">
          <span class="unit">¥</span><span>{{ product.price }}</span
          ><span class="linePrice">¥{{ product.tagPrice }}</span>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { formatImgUrl, http2https } from '@/utils/util';
import profit from '@/components/profit.vue';

export default {
  name: 'threeColProduct',
  components: {
    profit
  },
  props: {
    product: {
      type: Object,
      default: () => {}
    },
    index: {
      type: Number,
      default: 0
    }
  },
  data() {
    return {};
  },
  computed: {
    imgUrl() {
      if (
        this.product.productPicUrl &&
        this.product.productPicUrl.split(',')[0]
      ) {
        const productPicUrl = formatImgUrl(
          this.product.productPicUrl.split(',')[0],
          156,
          156
        );
        return http2https(productPicUrl);
      }
      return null;
    },
    isUserOfB() {
      return true;
    }
  },
  methods: {
    // 前往商品详情页
    goProductDetail() {
      this.$emit('goProductDetail');
    },
    shareProduct() {
      this.$emit('shareProduct');
    },
    addToCart() {
      this.$emit('addToCart');
    }
  }
};
</script>

<style lang="scss" scoped>
.three-col-item-wrap {
  width: 113px;
  background-color: #fff;
  border-radius: 6px;
  margin: 0 3px 10px;
  overflow: hidden;
  .img-wrap-box {
    position: relative;
    width: 113px;
    height: 113px;
    img {
      width: 113px;
      height: 113px;
      border-radius: 6px 6px 0 0;
      object-fit: cover;
      display: inline-block;
    }

    .profit--private {
      max-width: 113px;
    }

    .sellout {
      position: absolute;
      top: 0;
      right: 0;
      bottom: 0;
      left: 0;
      margin: auto;
      display: flex;
      justify-content: center;
      align-items: center;
      width: 65px;
      height: 65px;
      border-radius: 50%;
      color: #fff;
      font-size: 16px;
      background-color: rgba(0, 0, 0, 0.6);
    }

    .mark-img {
      position: absolute;
      top: 0;
      right: 10px;
      width: 19px;
      height: 21px;
      object-fit: cover;
      display: inline-block;
      border-radius: 0;
    }
  }

  .product-info-wrap {
    padding: 6px 6px 0;
    .product-name {
      font-size: 15px;
      font-family: PingFangSC-Regular;
      color: #333;
      line-height: 21px;
      margin-bottom: 3px;
    }
    .product-des {
      width: 101px;
      height: 34px;
      font-size: 12px;
      font-family: PingFangSC-Regular;
      color: #333;
      line-height: 17px;
      overflow: hidden;
    }
    .price-cart {
      display: flex;
      padding-top: 4px;
      justify-content: space-between;
      align-items: center;

      .price {
        font-size: 18px;
        font-family: DINAlternate-Bold, DINAlternate;
        font-weight: bold;
        color: rgba(230, 37, 37, 1);
        line-height: 26px;
      }
      .unit {
        font-size: 12px;
        margin-right: 2px;
        font-family: DINAlternate-Bold, DINAlternate;
        font-weight: bold;
      }
      .linePrice {
        text-decoration: line-through;
        font-size: 11px;
        font-family: DINAlternate-Bold, DINAlternate;
        font-weight: bold;
        color: rgba(153, 153, 153, 1);
        line-height: 14px;
        margin-left: 4px;
      }

      .cart {
        width: 24px;
        height: 24px;
      }
    }
  }

  .more_text {
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    word-break: break-all;
    height: 40px;
    line-height: 17px;
    overflow-y: hidden;
  }
}
</style>
